]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
tools/toolbox: Add `meson test` convenience wrapper
authorFlorian Müllner <fmuellner@gnome.org>
Fri, 12 Jan 2024 13:48:11 +0000 (14:48 +0100)
committerMarge Bot <marge-bot@gnome.org>
Mon, 15 Jan 2024 17:27:46 +0000 (17:27 +0000)
It can be fairly tedious to enter a toolbox and invoke `meson test`
with the right build directory, so add a companion script to the
existing meson-build.sh to handle that.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3114>

tools/toolbox/README.md
tools/toolbox/meson-test.sh [new file with mode: 0755]

index 056bb63e464786dbe32eb314600b11cb49e37e99..3f1ff5c79a5d3bf726a17094225d5a91ce419ecc 100644 (file)
@@ -31,6 +31,14 @@ the project.
 
 Run the script with `--help` to see available options.
 
+## meson-test.sh
+Run a meson project's test suite in a toolbox.
+
+The script wraps meson's `test` command to make invoking it inside a
+toolbox more convenient.
+
+Run the script with `--help` to see available options.
+
 ## run-gnome-shell.sh
 Run gnome-shell from a toolbox.
 
diff --git a/tools/toolbox/meson-test.sh b/tools/toolbox/meson-test.sh
new file mode 100755 (executable)
index 0000000..72631c2
--- /dev/null
@@ -0,0 +1,108 @@
+#!/bin/bash
+
+set -e
+
+DEFAULT_TOOLBOX=gnome-shell-devel
+CONFIG_FILE=${XDG_CONFIG_HOME:-$HOME/.config}/gnome-shell-toolbox-tools.conf
+
+usage() {
+  cat <<-EOF
+       Usage: $(basename $0) [OPTION…]
+
+       Run meson project tests in a toolbox
+
+       Options:
+         -t, --toolbox=TOOLBOX   Use TOOLBOX instead of the default "$DEFAULT_TOOLBOX"
+
+         --gdb                   Run test under gdb
+         --wrapper=WRAPPER       Wrapper to run tests with (e.g. valgrind)
+
+         --list                  List available tests
+
+         --suite=SUITE           Only run tests belonging to the given suite
+         --no-suite=SUITE        Do not run tests belonging to the given suite
+
+         --setup=SETUP           Which test setup to use
+         --test-args=TEST_ARGS   Arguments to pass to the specified test(s) or all tests
+
+         -v, --verbose           Do not redirect stdout and stderr
+         -q, --quiet             Produce less output to the terminal
+
+         -h, --help              Display this help
+
+       EOF
+}
+
+die() {
+  echo "$@" >&2
+  exit 1
+}
+
+find_toplevel() {
+  while true; do
+    grep -qs '\<project\>' meson.build && break
+    [[ $(pwd) -ef / ]] && die "Error: No meson toplevel found"
+    cd ..
+  done
+}
+
+# load defaults
+. $CONFIG_FILE
+TOOLBOX=$DEFAULT_TOOLBOX
+
+TEMP=$(getopt \
+  --name $(basename $0) \
+  --options 't:vqh' \
+  --longoptions 'toolbox:' \
+  --longoptions 'gdb' \
+  --longoptions 'wrapper:' \
+  --longoptions 'list' \
+  --longoptions 'suite:' \
+  --longoptions 'no-suite:' \
+  --longoptions 'setup:' \
+  --longoptions 'test-args:' \
+  --longoptions 'verbose' \
+  --longoptions 'quiet' \
+  --longoptions 'help' \
+  -- "$@") || die "Run $(basename $0) --help to see available options"
+
+eval set -- "$TEMP"
+unset TEMP
+
+MESON_ARGS=()
+
+while true; do
+  case $1 in
+    -t|--toolbox)
+      TOOLBOX=$2
+      shift 2
+    ;;
+
+    --list|--gdb|-v|--verbose|-q|--quiet)
+      MESON_ARGS+=($1)
+      shift
+    ;;
+
+    --wrapper|--suite|--no-suite|--setup|--test-args)
+      MESON_ARGS+=($1 $2)
+      shift 2
+    ;;
+
+    -h|--help)
+      usage
+      exit 0
+    ;;
+
+    --)
+      shift
+      break
+    ;;
+  esac
+done
+
+find_toplevel
+
+BUILD_DIR=build-$TOOLBOX
+
+toolbox run --container $TOOLBOX \
+  meson test -C $BUILD_DIR ${MESON_ARGS[*]} $@